// homemaking/tabs/index.js
Component({
  // 插槽
  options: {
  multipleSlots:true
  },
  /**
   * 组件的属性列表
   */
  properties: {
     list:{
       type:Array,
       value:[]
     }
  },

  /**
   * 组件的初始数据
   */
  data: {
    hint:0, //下滑线
    currentTarget:0,//传过来的左滑右滑
  },

  /**
   * 组件的方法列表
   */
  methods: {
<<<<<<< HEAD
    // 导航栏
  bindcut(e) {
    let {id} = e.currentTarget.dataset
    if(id === this.data.hint) {
      return
    }
=======
    handlswitchover (e) {
      // 如果tabs的index = currentTabIndex的index，让点击事件return，要不然会浪费性能
      const {index} = e.currentTarget.dataset
      if(index === this.data.currentTabIndex) {
            return
      }
      console.log(index)
>>>>>>> 6043a317c93d6fdc10271baf5995ab1c1feddbc3
      this.setData({
        hint:id
      })
<<<<<<< HEAD
      this.triggerEvent('change',{id})
  },
  // 滑动切换导航栏
  bindmove(e) {
    let {currentTarget} = e
    let hint = this.data.hint
    let targetTabIndex = hint + currentTarget
    console.log(targetTabIndex)
    if(targetTabIndex < 0 || targetTabIndex > this.data.list.length - 1) {
      return
=======
      this.triggerEvent('change',{index})
    },
    // 获取wxs传过来的1还是-1
    handleTouchMove(e) {
      const {num} = e
      const {currentTabIndex} = this.data
      const targetTabIndex = currentTabIndex + num
      console.log(targetTabIndex)
      console.log(this.data.tabs)
      // 数组的下标不能是负数，向右划是-1，0+-1还是负数，所以要加判断
      if(targetTabIndex < 0 || targetTabIndex >this.data.tabs.length - 1) {
             return
      }
      // 模拟数据类型
      const customEvent = {
        currentTarget : {
          dataset : {
            index:targetTabIndex
          }
      }
      }
      this.handlswitchover(customEvent)
    },
    handleTouchstart(e) {
      console.log(e)
    },
    handletouchend(e) {
      console.log(e)
>>>>>>> 6043a317c93d6fdc10271baf5995ab1c1feddbc3
    }
    let index = {
      currentTarget: {
      dataset: {
        id:targetTabIndex
      }
    }
  }
  this.bindcut(index)
  },
  }
})
